﻿
#region Usings
using System;

using PolyGameEngine.GamePieces;
using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion


namespace PolyMorph.CustomGamePieces
{
    public class GravityShifTile: Tile
    {
        public Texture2D shiftTileTexture;
        int mod = 1;
        public GravityShifTile(PhysicsGame PhysicsGame, World World, Material Material, Vector2 Position, float Rotation, int saveLineIndex, Texture2D ShiftTileTexture)
            : base(PhysicsGame, World, Material, Position, Rotation, 50, 50, 1, saveLineIndex, "GravityShift")
        {
            shiftTileTexture = ShiftTileTexture;
        }

        public override bool HandleDefaultCollision(Fixture ThisFixture, Fixture OtherFixture, Contact Contact)
        {
            if ((int)MathHelper.ToDegrees(Math.Abs(MathHelper.WrapAngle(rotation))) == 0)
                mod = -1;
            else
                mod = 1;
            world.Gravity.Y =mod*Math.Abs(world.Gravity.Y);

            return base.HandleDefaultCollision(ThisFixture, OtherFixture, Contact);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Draw(shiftTileTexture, position + _ScreenOffset, null, Color.White, rotation, sprite.Origin, 1, SpriteEffects.None, 0);
        }

      

    }
}